package com.timothy.junk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sina.util.StringUtil;
import com.timothy.junk.R;
import com.timothy.junk.tfund.bean.TFundResult;

import java.util.HashMap;
import java.util.List;

public class TFundAdaptor extends BaseAdapter {
	private Context 					mContext;
	private List<TFundResult> 		listItems;
	private LayoutInflater 				mInflater;

	HashMap<Integer,View> viewMap = new HashMap<Integer,View>();

	static class ViewHolder{
		public TextView tFundIndex;
        public TextView tFundName;
        public TextView tFundRDays;
        public TextView tFundDiscount;
        public TextView tFundTReturn;
	    public TextView tFundYReturn;
	 }

	public TFundAdaptor(Context context, List<TFundResult> data) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context); 
		this.listItems = data;
	}

	
	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;  
        if (convertView == null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.tfund_list_item, null);
            
            holder.tFundIndex = (TextView) convertView.findViewById(R.id.tFundIndex);
			holder.tFundName = (TextView) convertView.findViewById(R.id.tFundName);
			holder.tFundRDays = (TextView) convertView.findViewById(R.id.tFundRDays);
			holder.tFundDiscount = (TextView) convertView.findViewById(R.id.tFundDiscount);
			holder.tFundTReturn = (TextView) convertView.findViewById(R.id.tFundTReturn);
			holder.tFundYReturn = (TextView) convertView.findViewById(R.id.tFundYReturn);
			
            convertView.setTag(holder);  
        }else {  
            holder = (ViewHolder) convertView.getTag();  
        }

        TFundResult bean = listItems.get(position);
        holder.tFundIndex.setText(String.valueOf(position+1));
		holder.tFundName.setText(bean.getTfundName());
		holder.tFundRDays.setText(String.valueOf(bean.getRemainingDays()));
		holder.tFundDiscount.setText(StringUtil.formatData2Deci(bean.getDiscount()*100)+"%");
		holder.tFundTReturn.setText(StringUtil.formatData2Deci(bean.getTotalReturn()*100)+"%");
		holder.tFundYReturn.setText(StringUtil.formatData2Deci(bean.getYearReturn()*100)+"%");

        return convertView; 
        
	}

}
